package com.yx.sql.controller;

import cn.hutool.json.JSONUtil;
import com.yx.common.core.domain.R;
import com.yx.common.core.web.controller.BaseController;
import com.yx.common.core.web.page.TableDataInfo;
import com.yx.common.websocket.server.WebSocketServer;
import com.yx.common.websocket.vo.MsgResponseVo;
import com.yx.sql.convert.DbConnectConverter;
import com.yx.sql.entity.DbConnect;
import com.yx.sql.entity.vo.DbConnectVo;
import com.yx.sql.service.ConnectionService;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author kai.yang
 * @date 2023/3/24 22:57
 */
@Slf4j
@Schema(name = "数据源连接配置管理")
@RestController
@RequestMapping("/datasource/connection")
public class ConnectionController extends BaseController {

    @Resource
    ConnectionService connectionService;

    /**
     * 获取参数配置列表
     * pageSize=10&pageNum=1&orderByColumn=createTime&isAsc=desc&deptId=
     * &parentId=&loginName=&phonenumber=&status=&
     * params%5BbeginTime%5D=&params%5BendTime%5D=
     */
    @Schema(name="数据源连接配置管理-分页模式")
    @PostMapping("/list")
    public TableDataInfo list(DbConnectVo dbConnectVo)
    {
        startPage();
        List<DbConnect> list = connectionService.getConnectList(dbConnectVo);
        // 获取分页信息
        TableDataInfo dataTable = getDataTable(list);
        List<DbConnectVo> collect = list.stream().map(DbConnectConverter::convertToVo).collect(Collectors.toList());
        dataTable.setRows(collect);
        return dataTable;
    }

    @Schema(name="数据源连接配置管理-分页模式")
    @PostMapping("/list1")
    public TableDataInfo list1(DbConnectVo dbConnectVo)
    {
        startPage();
        //实体对象可以直接返回，或者在xml中写查询返回 DbConnectVo也行【查询的要和返回的一致才行，才能获取到总数】
        List<DbConnect> list = connectionService.getConnectList(dbConnectVo);
        // 获取分页信息
        return getDataTable(list);
    }




}
